#include "HookShell32.h"
#include "SafeBox.h"
#include "HookApi.h"

PFN_ShellExecuteExW REAL_ShellExecuteExW = NULL;
PFN_SHOpenFolderAndSelectItems REAL_SHOpenFolderAndSelectItems = NULL;


BOOL STDAPICALLTYPE HOOK_ShellExecuteExW(_Inout_ SHELLEXECUTEINFOW* pExecInfo)
{
    return REAL_ShellExecuteExW(pExecInfo);
}

HRESULT STDAPICALLTYPE HOOK_SHOpenFolderAndSelectItems(_In_ PCIDLIST_ABSOLUTE pidlFolder,
    UINT cidl, _In_reads_opt_(cidl) PCUITEMID_CHILD_ARRAY apidl, DWORD dwFlags)
{
    return REAL_SHOpenFolderAndSelectItems(pidlFolder, cidl, apidl, dwFlags);
}

int Hook_Shell32()
{
    std::vector<APIINFO>* vecInfo = GetAPIInfo(L"Shell32.dll");
    if (NULL == vecInfo) {
        return -1;
    }

    HOOKAPI(*vecInfo, ShellExecuteExW);
    HOOKAPI(*vecInfo, SHOpenFolderAndSelectItems);

    CommitHook(L"Shell32.dll", *vecInfo);
    return vecInfo->size();
}

int UnHook_Shell32()
{
    std::vector<APIINFO>* vecInfo = GetAPIInfo(L"Shell32.dll"); if (NULL == vecInfo)
    {
        return -1;
    }
    CommitUnHook(L"Shell32.dll", *vecInfo);
    ClearAPIInfo(L"Shell32.dll");
    return 0;
}
